package com.chijun.mform.field.impl;


import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;

import com.chijun.mform.create.mode.FormField;
import com.chijun.mform.field.BaseField;
import com.example.ccj.u.StringUtils;
import com.example.ccj.u.message.UiMessageUtils;
import com.example.ccj.u.text.TextInputType;

import io.reactivex.ObservableEmitter;

/**
 * 多行文字
 * @author 驰珺
 * whechat   : chijun9
 * create at : 2024/12/23 15:44
 */
public class FieldFor05Number extends BaseField {
    public FieldFor05Number(){
        super();
    }

    @Override
    public View getWritelView(Context context, WriteFormClass writeFormClass) {
        FormField formField = writeFormClass.formField;
        //提示文本
        if (formField.getHint() != null) writeFormClass.fieldFullContentView.setHint(formField.getHint());
        //输入文本颜色
        if (formField.getTextColor() != 0) writeFormClass.fieldFullContentView.setTextColor(formField.getTextColor());
        //是否只读
        if (formField.isReadOnly()) {
            writeFormClass.fieldFullContentView.setKeyListener(null);
            writeFormClass.fieldFullContentView.setFocusable(false);
        }

        //默认文本
        String textFieldZanCunData = getTextFieldZanCunData(context,"fieldId=?",String.valueOf(formField.getId()));
        if (textFieldZanCunData == null) textFieldZanCunData = formField.getDefaultContent();
        if (!StringUtils.isEmpty(textFieldZanCunData)) {
            writeFormClass.fieldFullContentView.setText(textFieldZanCunData);
            saveValue = textFieldZanCunData;
            writeFormClass.inputIsOK = true;
        }


        //文本改变事件
        writeFormClass.fieldFullContentView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}
            @Override
            public void afterTextChanged(Editable s) {
                writeFormClass.inputIsOK = check(s,formField,writeFormClass.fieldFullWriteErrorView);
                UiMessageUtils.getInstance().send(JI_SUAN_GONG_SHI, formField.getId()+","+s);
            }
        });

        if (formField.getLittleNum() > 0) {
            TextInputType.setEditTextInPutTypeToDouble(writeFormClass.fieldFullContentView,100,formField.getLittleNum());
        } else {
            TextInputType.setEditTextInPutTypeToDouble(writeFormClass.fieldFullContentView,100,2);
        }


        return writeFormClass.view;
    }

    @Override
    protected View getShowFullView(Context context, FullClass fullModel) {
        //字段名属性设置
        fullModel.setFieldProperty();
        //设置字段值
        fullModel.setContentProperty();
        return fullModel.layout;
    }

    @Override
    protected View getFieldInstallView(Context context, InstallClass installClass) {
        ObservableEmitter<ViewGroup> emitter = installClass.emitter;

        emitter.onNext(installClass.getCompanyConfigView()); //单位
        emitter.onNext(installClass.getNumberView());        //小数位数设置
        emitter.onNext(installClass.getIsMastView());        //是否必填
        emitter.onNext(installClass.getIsCanScanView());     //是否可扫码
        emitter.onNext(installClass.getIsPrintView());        //是否参与打印

        return installClass.v;
    }

}
